package leetcode;

import java.util.ArrayList;
import java.util.List;

public class LC44 {
    public static void main(String[] args) {

    }
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> ans = new ArrayList<>();
        rightSideView(root,ans,0);
        return ans;
    }
    public void rightSideView(TreeNode root,List<Integer> ans, int i) {
        if (root == null) return;
        if (ans.size() == i)
            ans.add(i,root.val);
        else
            ans.set(i, root.val);
        rightSideView(root.left,ans,i+1);
        rightSideView(root.right,ans,i+1);
    }
}
